{% extends "layouts/baseview.html" %}
{% load i18n %}
{% load short_uri %}

{%block title%}{{pagename}}{%endblock%}

{% block stylesheet %}
<link rel="stylesheet" href="/css/code-min.css" />
{% endblock %}

{%block ready_js%}
		$('#btn_del').confirm('{%trans "Are you sure delete this page?"%}', '{%trans "Yes"%}', '{%trans "No"%}', function() {
		    $('#del_wiki').submit();
		});
		
		$('#btn_add_file').click(function() {
		    $('#add_file_form').toggle(100);
		});
		
		$('#btn_files_submit').click(function() {
		    $('#add_file_form form').submit();
		    $('#add_file_form').toggle(100);
		});
		
		
		$('#add_file_line').click(function() {
		    if ($('#files .file_line').length >= 5) {
			return;
		    }
		    $('#files').append('<div class="file_line"><input type="file" name="attachment"/></div>');
		});
		
		$('.btn_delete_file').click(function(e){
		    var fid = $(this).attr('data-id');
		    var line = $(this).parent();
		    sure(e, '{%trans "Are you sure delete this file?"%}', '{%trans "Yes"%}', '{%trans "No"%}', function() {
			q_get('delfile', {'fid': fid}, function (result) {
			    line.remove();
			}, function (result) {
			    alert('{%trans "can not remove this file!"%}');
			});
		    });
		});

{%endblock%}


{%block main-block%}
<div class="d-p-project-content d-p-project-document">
	
	{%if wiki%}
		<div class="d-p-project-documenttop">
		<p class="d-p-project-info">
		    <span>{%trans "Creater"%}:{{wiki.user}}</span>
		    <span>{%trans "CreateTime:"%}{{wiki.ctime|date:"Y年m月d日"}}</span>
	    </p>
	     <ul class="d-p-project-operate">
			    {%if can_op%}
						<form id="del_wiki" action="{{project|url}}del_wiki/" method="POST">
							{%csrf_token%}
							<input type="hidden" name="wiki_id" value="{{wiki.id}}"/>
						</form>
					   
					        <li style="background:none;">
					        <a href="{{project|url}}wiki/index/">{%trans "Wiki index"%}</a></li>
					        <li><a href="{{project|url}}wikis/">{%trans "All wiki pages"%}</a></li>
					        <li><a href="{{project|url}}raw_wiki/{{wiki.path}}/">{%trans "Raw text"%}</a></li>
					        <li><a href="{{project|url}}wiki_changes/{{wiki.path}}">{%trans "changes"%}</a></li>
					        <li><a href="{{project|url}}edit_wiki/{{wiki.path}}">{%trans "edit"%}</a></li>
					        <li><a id="btn_del" href="javascript:;" >{%trans "delete"%}</a></li>
		
				{%endif%}
		  </ul>
		</div>	
				<div class="d-p-project-documentcontent">
				  {{wiki.content|wikitext:wiki}} 
				</div>
		{%if can_op%}	
				
			<ul class="d-p-project-operate">			
			<li style="background:none;">
			<a id="btn_add_file" href="javascript:;">{%trans "Add attachment"%}</a></li>	
			</ul>

		{%endif%}
		
		
			{%if can_op%}
				<div id="add_file_form" style="display:none" >
				  <form action="" method="POST" enctype="multipart/form-data">
				    {%csrf_token%}
				    <input type="hidden" name="wiki_id" value="{{wiki.id}}"/>

					    <a href="javascript:;" id="add_file_line">{%trans "Append file"%}</a>

				    <div id="files">
				      <div class="file_line">
					<input type="file" name="attachment"/>
				      </div>
				    </div>
				  </form>				
				  <p>
				    <a href="javascript:;" class="button" id="btn_files_submit">{%trans "submit"%}</a>
				  </p>
				</div>
			{%endif%}
			
			{%include "main/files.html"%}	

		
	{%else%}
		<div class="d-p-project-documenttop">
				<p class="d-p-project-info">
			
				  {%trans "Not found page"%} <!-- <strong>{{pagename}}</strong> -->
				</p>
				 
			
			  {%if can_op%}
				<ul class="d-p-project-operate">
					   
					       <li style="background:none;">
						  
						   <a href="{{project|url}}edit_wiki/{{pagename}}/">{%trans "Create Page"%}</a></li>
						
						   <li><a href="{{project|url}}wikis/">{%trans "All wiki pages"%}</a></li>
					   
				</ul>
			  {%endif%}
			  
 		 </div>
		</ul>


	
	
	
	
	
	
	
	
	
	

	{%endif%}

	


</div>
{%endblock%}
